<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>知道秘密的人数</title>
</head>
<body>
  <script>
    function fn(n, delay, forget) {
      let res = Array(forget).fill(0)
      const MOD = 10 ** 9 + 7;
      res[0] = 1
      while (--n) {
        let sum = res.slice(delay - 1, forget - 1).reduce((sum, num) => (sum + num) % MOD, 0)
        for (let i = forget - 1; i >= 1; i--) {
          res[i] = res[i - 1]
        }
        res[0] = sum
      }
      let count = res.reduce((sum, num) => (sum + num) % MOD, 0)
      return count
    }
    console.log(fn(6, 2, 4))
  </script>
</body>
</html>